//
//  AppDelegate.swift
//  Mars Proxy
//
//  Created by PowerfullClean on 2023/10/16.
//

import UIKit

@main
class MAPYAppDelegate: UIResponder, UIApplicationDelegate {



    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        MAPYManager.mapy_manager.mapy_createDataBase()
        MAPYManager.mapy_manager.mapy_vpnList1Request()
        MAPYManager.mapy_manager.mapy_vpnList2Request()
        mapy_window?.backgroundColor = .white
        mapy_window?.rootViewController = UINavigationController(rootViewController: MAPYLaunchViewController())
        mapy_window?.makeKeyAndVisible()
        return true
    }
    func applicationWillTerminate(_ application: UIApplication) {
        // 关闭应用，使用当前管理类关闭连接
        MAPYManager.mapy_manager.mapy_vpnManager?.connection.stopVPNTunnel()
    }
    func mapy_refreshMainVC() {
        mapy_window?.rootViewController = UINavigationController(rootViewController: MAPYHomeViewController())
        mapy_window?.makeKeyAndVisible()
    }
    @objc lazy var mapy_window: UIWindow? = {
        return UIWindow(frame: UIScreen.main.bounds)
    }()
    
    @objc class func mapy_shared() -> MAPYAppDelegate {
        return UIApplication.shared.delegate as! MAPYAppDelegate
    }
}

